﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Yipusoft.Exercitation.BLL;
using Yipusoft.Exercitation.Model;
using Yipusoft.Account.Model;

public partial class Combat_SquadronList : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
	
	UserInfo user = Yipusoft.Account.BLL.User.GetUser(User.Identity.Name);	
        if (!IsPostBack)
        {
            ListPageContral1.SetFirstPage();
            Bind(0);           
        }
    }

    public void lnbtnReceive_Command(object sender, CommandEventArgs e)
    {
        TaskSquadronInfo info = TaskSquadron.GetTaskSquadron(new Guid(e.CommandArgument.ToString()));
        if (info == null)
            return;
        info.IsAccept = true;
        info.AcceptUser = User.Identity.Name;
        info.AcceptDate = DateTime.Now;
        TaskSquadron.Update(info);

        TaskSoldiers.SetTaskSoldiers(new Guid(e.CommandName.ToString()), info.DepartmentID);

        ListPageContral1.SetFirstPage();
        Bind(0);
    }
    public void lnbtnInPut_Command(object sender, CommandEventArgs e)
    {
        ListPageContral1.SetFirstPage();
        Bind(0);  
    }

    public void ListPageContral1_PageSizeChange(int pageSize, int PageIndex)
    {
        Bind(PageIndex);
    }

    public bool GetDepartment()
	{
		return Yipusoft.Account.BLL.User.GetUser(User.Identity.Name).DepartmentID.Substring(0,4)=="1302";
	}

    //任务是否过期
    public bool IsTaskExpired(object taskID)
    { 
  	//if (Yipusoft.Account.BLL.User.GetUser(User.Identity.Name).DepartmentID == "1308307" 
       //     && (GetTaskDate(taskID) == "2010-7-25")
	//)
       // {
       //     return false;
       // }

        if(Yipusoft.Exercitation.BLL.TaskBase.GetTaskBase(new Guid(Eval("TaskID").ToString())).EndDate < DateTime.Now)
        {
            if(!(bool)Eval("IsAccept"))
            {
                return true;
            }
        }

        return false;
    }

    private void Bind(int pageIndex)
    {
        UserInfo user = Yipusoft.Account.BLL.User.GetUser(User.Identity.Name);
        if (user == null)
            return;
        ListPageContral1.ItemCount = TaskSquadron.GetCount(" DepartmentID='" + user.DepartmentID + "'");
        UserGrid.DataSource = TaskSquadron.GetList("AcceptDate", "Desc", " DepartmentID='" + user.DepartmentID + "' ", ListPageContral1.PageSize, pageIndex);
        UserGrid.DataBind();

    }
    //任务标题
    public string GetTaskTitle(object taskID)
    {
        if (taskID == null)
            return "";
        TaskBaseInfo taskInfo = TaskBase.GetTaskBase(new Guid(taskID.ToString()));
        return taskInfo != null ? taskInfo.TaskTitle : "";
    }
    //任务时间
    public string GetTaskDate(object taskID)
    {
        if (taskID == null)
            return "";
        TaskBaseInfo taskInfo = TaskBase.GetTaskBase(new Guid(taskID.ToString()));
        return taskInfo != null ? taskInfo.SetOnDate.ToString("yyyy-MM-dd") : "";
    }
    public string GetTaskID(object taskID)
    {
        return taskID.ToString();
    }
    protected void UserGrid_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label ID = (Label)e.Row.FindControl("ID");
            ID.Text = ((ListPageContral1.CurrentPageIndex * ListPageContral1.PageSize) + (e.Row.RowIndex + 1)).ToString();
            //当鼠标放上去的时候 先保存当前行的背景颜色 并给附一颜色 
            e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#F5F5F5',this.style.fontWeight='';");
            //当鼠标离开的时候 将背景颜色还原的以前的颜色 
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor,this.style.fontWeight='';");
        }
    }
}
